package com.think.archive.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.think.archive.service.InfoArchiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class InfoArchiveServiceImpl implements InfoArchiveService {

    private static final String COLLECTION_NAME = "info_archive";

    @Autowired
    MongoTemplate mongoDB;

    public <T> T insert(T t){
        return mongoDB.insert(t,COLLECTION_NAME);
    }

    @Override
    public JSONObject getArchiveById(String archiveId) {
        Query query=new Query();
        Criteria criteria=Criteria.where("_id").is(archiveId);
        query.addCriteria(criteria);
        return mongoDB.findOne(query,JSONObject.class,COLLECTION_NAME);
    }


}
